using System.Drawing;
using System.Drawing.Drawing2D;

namespace DrawTools.Editor.CanvasFigures
{
  /// <summary>
  ///   Rectangle graphic object
  /// </summary>
  public class CanvasRectangle : CanvasRectangleBase
  {
    public CanvasRectangle() : this(0, 0, 1, 1) {}

    public CanvasRectangle(int x, int y, int width, int height) : base(x, y, width, height) {}

    /// <summary>
    ///   Draw rectangle
    /// </summary>
    /// <param name="graphics"></param>
    public override void Draw(Graphics graphics)
    {
      using (Pen pen = CreateBorderPen())
      using (Brush brush = CreateBackBrush())
      {
        Rectangle rect = GetNormalizedRectangle(Rectangle);
        //DrawFuzzyLine(g, new Point(rect.X, rect.Bottom), new Point(rect.Right, rect.Bottom) );
        //DrawFuzzyLine(g, new Point(rect.Right, rect.Top), new Point(rect.Right, rect.Bottom));

        if (LineType != LineType.None || BackgroundOpacity > 0)
        {
          var path = new GraphicsPath();
          path.AddRectangle(rect);
          path.CloseAllFigures();

          DrawFuzzyPath(graphics, path, BorderColor);
        }

        graphics.FillRectangle(brush, rect);

        if (LineType != LineType.None)
        {
          graphics.DrawRectangle(pen, rect);
        }
      }
    }
  }
}